.section .data
	str:
		.string "a+"
	filename:
		.string "data.txt"
.section .bss
    .lcomm fp,8
.section .text
.equ PERSON_SIZE,76
.section .text
.global LoadContact
.type LoadContact,@function
LoadContact:
	nop
	push %rbp
	mov %rsp,%rbp
	sub $24,%rsp
	mov %rdi,-8(%rbp)
#打开文件	
    mov $filename,%rdi
    mov $str,%rsi #以只读的方式打开
	call fopen
    test %rax,%rax
	js 1f
	jz 1f
	movq %rax,-16(%rbp) #文件指针
	movq -8(%rbp),%rbx
#循环读取文件内容到堆内存
    movl $PERSON_SIZE,%edi
    call malloc
    test %rax,%rax
    jz 1f
    js 1f
    movq %rax,fp
0:
	movq fp,%r12
	movq %r12,%rdi
	movl $PERSON_SIZE,%esi
	movl $1,%edx
	movq -16(%rbp),%rcx
	call fread
	cmpq $0,%rax
	ja 2f
	movq $0,%rax
	movq fp,%rdi
	call free
1:
#关闭文件
	mov $0,%rax
	mov -16(%rbp),%rdi
	call fclose
	leaveq 
	retq
2:
#将数据拷贝到堆内存 并增加通讯录大小检查是否需要扩容
	movq %rbx,%rdi
	call CheckCapacity
	movl 12(%rbx),%r8d #sz
	imull $PERSON_SIZE,%r8d #堆内存偏移量
	movq (%rbx),%r9 #堆内存首地址
	movslq %r8d,%r8
	leaq (%r9,%r8,1),%rax #堆区地址
#将写入栈变量上的数据拷贝到堆区
	mov $PERSON_SIZE,%rcx
	cld
	mov %rax,%rdi
	mov %r12,%rsi
	rep movsb
#sz++		
	incl 12(%rbx) 
	jmp 0b	
